home *** CD-ROM | disk | FTP | other *** search
- From: tony@online.tmx.com.au (Tony Cook)
- Message-ID: <199603312308.JAA29018@online.tmx.com.au>
- X-Original-Date: Mon, 1 Apr 1996 09:08:43 +1000
- Path: in2.uu.net!bounce-back
- Date: 01 Apr 96 04:13:59 GMT
- Approved: fjh@cs.mu.oz.au
- Newsgroups: comp.std.c++
- Subject: Re: double const declarations
- Organization: Home
- References: <4jc2fa$bqu@arl-news-svc-2.compuserve.com> <4jdvnj$o35@mulga.cs.mu.OZ.AU> <QQajel16319.199603292150@relay1.UU.NET>
- X-Newsreader: TIN [version 1.2 PL2]
- X-Auth: PGPMoose V1.1 PGP comp.std.c++
- iQBFAgUBMV9Ye+EDnX0m9pzZAQH9hQF/ajcQGL1RX5XoeYP6FfcrhO7SLlemwlON
- x6cOtMR1rYVjdBlqfSEy0dT+BEgL0krN
- =LR1x
-
- James Christodouleas (jchristo@mit.edu) wrote:
- : In article <4jdvnj$o35@mulga.cs.mu.OZ.AU>, fjh@munta.cs.mu.OZ.AU (Fergus
- : Henderson) wrote:
-
- : > Philippe Verdy <100105.3120@compuserve.com> writes:
- : >
- : > >template <class T, class CT>
- : > >class SmartPtr2 {
- : > > SmartPtr2(T* p) { mp = const_cast<CT>(p) ; }
- : > > CT & Dereference() {
- : > > return *mp ;
- : > > }
- : > > private :
- : > > CT *mp ;
- : > >} ;
- : > >template <class T> class ConstSmartPtr : SmartPtr<T, T> {} ;
- : > >template <class T> class FreeSmartPtr : SmartPtr<T, const T> {} ;
- : >
- : > You forgot to delegate the constructors.
- : >
- : > (Of course, if C++ supported tempate typedefs, there wouldn't be
- : > any need to delegate constructors in examples like this.
- : > Unfortunately it doesn't.)
-
- : What does it mean to "delegate constructors?" I looked it up in Coplien,
- : Advanced C++, and he talks about delegation to mean different classes
- : sharing functionality dynamically.
-
- He means that the new classes, ConstSmartPtr and FreeSmartPtr do not
- have constructors, and cannot be created, so constructors that
- simply pass on the parameters are required (delegation).
-
- There's another problem anyway - Phillippe used private inheritence,
- so a user cannot access the Dereference member function anyway.
-
- [Moderator's note: and `SmartPtr' should be `SmartPtr2',
- and `const_cast<CT>' should be `const_cast<CT*>'. This is
- why it is a good idea to try compiling your examples
- before posting them ;-). -fjh. ]
-
- --
- Tony Cook - tony@online.tmx.com.au
- 100237.3425@compuserve.com
- ---
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-